package cn.sczhyt.modules.szhy.service.impl;

import cn.sczhyt.common.exception.RRException;
import cn.sczhyt.common.utils.PageUtils;
import cn.sczhyt.common.utils.Query;
import net.sf.json.JSONArray;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;

import cn.sczhyt.modules.szhy.dao.MeetingReceiverDao;
import cn.sczhyt.modules.szhy.entity.MeetingReceiverEntity;
import cn.sczhyt.modules.szhy.service.MeetingReceiverService;


@Service("meetingReceiverService")
public class MeetingReceiverServiceImpl extends ServiceImpl<MeetingReceiverDao, MeetingReceiverEntity> implements MeetingReceiverService {
    @Autowired
    private MeetingReceiverDao meetingReceiverDao;
//    @Autowired
//    private UserUserGroupDao userUserGroupDao;
    @Override
    public PageUtils queryPage(Map<String, Object> params) {
        IPage<MeetingReceiverEntity> page = this.page(
                new Query<MeetingReceiverEntity>().getPage(params),
                new QueryWrapper<MeetingReceiverEntity>()
        );

        return new PageUtils(page);
    }

//    @Override
//    public void saveReceiver(String meetingId, String userIds) {
//        //参会人员存储
//        if (userIds == null) {
//            throw new RRException("请选择参会人员！", 201);
//        } else {
//            //获取参会人的ID及姓名然后保存
//            JSONArray jsonArray = JSONArray.fromObject(userIds);
//            for (int i = 0; i < jsonArray.size(); i++) {
//                if (jsonArray.getJSONObject(i).has("userId")) {
//                    // 选择单个参会人员时
//                    MeetingReceiverEntity meetingReceiverEntity = new MeetingReceiverEntity();
//                    meetingReceiverEntity.setUserId(jsonArray.getJSONObject(i).get("userId").toString());
//                    meetingReceiverEntity.setUserName(jsonArray.getJSONObject(i).get("userName").toString());
//                    meetingReceiverEntity.setMeetingId(meetingId);
//                    meetingReceiverDao.insert(meetingReceiverEntity);
//                } else {
//                    //选择群组时
//                    String groupId = jsonArray.getJSONObject(i).get("groupId").toString();
////                    List<UserUserGroupEntity> userUserGroupEntityList = userUserGroupDao.findByGroupId(groupId);
////                    for (UserUserGroupEntity userUserGroupEntity : userUserGroupEntityList) {
//                        MeetingReceiverEntity meetingReceiverEntity = new MeetingReceiverEntity();
//                        meetingReceiverEntity.setUserId(userUserGroupEntity.getUserId());
//                        meetingReceiverEntity.setUserName(userUserGroupEntity.getUserName());
//                        meetingReceiverEntity.setMeetingId(meetingId);
//
//                        meetingReceiverDao.insert(meetingReceiverEntity);
//                    }
//                }
//            }
//        }

//    }

}